package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.BasicStatusModel;
import com.kbbywyclient.data.model.base.BaseModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.SettingContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Description:
 * Created by FHW
 * on 2017/5/3
 */

public class SettingPresenter extends BasePresenter implements SettingContract.Presenter {

    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    private SettingContract.View view;

    @Inject
    public SettingPresenter(SettingContract.View view) {
        this.view = view;

    }

    @Override
    public void getBasicStatus(String SalesID) {
        rsaJsonUtil.put("SalesID", SalesID);
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getBasicStatus(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<BasicStatusModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(BasicStatusModel basicStatusModel) {
                        view.loadSucStatus(basicStatusModel.getData());
                    }
                });
    }

    @Override
    public void getModifyTableNotice(String SalesID, String SendInfo) {
        rsaJsonUtil.put("SalesID", SalesID);
        rsaJsonUtil.put("SendInfo", SendInfo);
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getModifyTableNotice(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<BaseModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(BaseModel baseModel) {
                        view.loadSucNotice(baseModel);
                    }
                });
    }
}
